package com.mmall.controller.protal;

import com.github.pagehelper.PageInfo;
import com.mmall.common.ServerResponse;
import com.mmall.service.IProductService;
import com.mmall.vo.ProductDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created By 陈吉鑫
 * on 14:27 2017/8/29
 */
@Controller
@RequestMapping("/product/")
public class ProductController {

    @Autowired
    private IProductService iProductService;

    /**
     * 前端得到商品的详细信息
     * @param productId
     * @return
     */
    @RequestMapping(value="detail.do",method= RequestMethod.POST)
    @ResponseBody
    public ServerResponse<ProductDetailVo> detail(Integer productId){
        return iProductService.getProductDetail(productId);
    }

    /**
     * 前端用户收索功能
     * 通过ProductName和categoryId收索商品信息 并且带有分页和排序功能
     * 局限性是 本排序只是价格排序
     * @param keyword
     * @param categoryId
     * @param pageNum
     * @param pageSize
     * @param orderBy
     * @return
     */
    @RequestMapping(value="list.do",method= RequestMethod.POST)
    @ResponseBody
    public ServerResponse<PageInfo> list(@RequestParam(value="keyword",required=false)String keyword,
                                         @RequestParam(value ="categoryId",required =false)Integer categoryId,
                                         @RequestParam(value ="pageNum",defaultValue ="1")Integer pageNum,
                                         @RequestParam(value ="pageSize",defaultValue ="10")Integer pageSize,
                                         @RequestParam(value = "orderBy",defaultValue = "")String orderBy){
        return iProductService.getProductByKeywordCategory(keyword,categoryId,pageNum,pageSize,orderBy);
    }





}
